package com.netty.handler;

import com.netty.common.protocol.RpcDecoder;
import com.netty.common.protocol.RpcEncoder;
import com.netty.common.protocol.RpcRequest;
import com.netty.common.protocol.RpcResponse;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;

public class RpcClientInitializer extends ChannelInitializer<SocketChannel>{

	@Override
	protected void initChannel(SocketChannel ch) throws Exception {
		ChannelPipeline cp = ch.pipeline();
		cp.addLast(new RpcEncoder(RpcRequest.class));
		cp.addLast(new LengthFieldBasedFrameDecoder(65536, 0, 4, 0, 0));
		cp.addLast(new RpcDecoder(RpcResponse.class));
		cp.addLast(new RpcClientHandler());
		
	}

}
